package com.dzsw.javabase.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicProxy implements InvocationHandler {

    private Object target;

    public DynamicProxy(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before do business.");
        if (method.getName().equals("doSomething")) {
            args[0] = "This is " + args[0] + ".";
        }
        Object result = method.invoke(target, args);
        System.out.println("after do business.");
        return result;
    }
}
